package com.gxgy.web.controller;

import com.gxgy.common.annotation.Log;
import com.gxgy.common.core.controller.BaseController;
import com.gxgy.common.core.domain.R;
import com.gxgy.common.enums.BusinessType;
import com.gxgy.common.utils.poi.ExcelUtil;
import com.gxgy.web.domain.TGoods;
import com.gxgy.web.service.ITGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 商品管理Controller
 *
 * @author mobin
 * @date 2024-11-09
 */
@Api(tags = "商品管理")
@RestController
@RequestMapping("/web/goods")
public class TGoodsController extends BaseController {
    @Autowired
    private ITGoodsService tGoodsService;

    /**
     * 查询商品管理列表
     */
    @ApiOperation("查询商品管理列表")
    @PreAuthorize("@ss.hasPermi('web:goods:list')")
    @GetMapping("/list")
    public R<List<TGoods>> list(TGoods tGoods) {
        startPage();
        List<TGoods> list = tGoodsService.selectTGoodsList(tGoods);
        return R.ok(list);
    }

    /**
     * 导出商品管理列表
     */
    @ApiOperation("导出商品管理列表")
    @PreAuthorize("@ss.hasPermi('web:goods:export')")
    @Log(title = "商品管理" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TGoods tGoods) {
        List<TGoods> list = tGoodsService.selectTGoodsList(tGoods);
        ExcelUtil<TGoods> util = new ExcelUtil<TGoods>(TGoods.class);
        util.exportExcel(response, list, "商品管理数据");
    }

    /**
     * 获取商品管理详细信息
     */
    @ApiOperation("获取商品管理详细信息")
    @PreAuthorize("@ss.hasPermi('web:goods:query')")
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Long id) {
        return R.ok(tGoodsService.selectTGoodsById(id));
    }

    /**
     * 新增商品管理
     */
    @ApiOperation("新增商品管理")
    @PreAuthorize("@ss.hasPermi('web:goods:add')")
    @Log(title = "商品管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public R<Object> add(@RequestBody TGoods tGoods) {
        tGoods.setCreateBy(getUsername());
        return R.ok(tGoodsService.insertTGoods(tGoods));
    }

    /**
     * 修改商品管理
     */
    @ApiOperation("修改商品管理")
    @PreAuthorize("@ss.hasPermi('web:goods:edit')")
    @Log(title = "商品管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Object> edit(@RequestBody TGoods tGoods) {
        return R.ok(tGoodsService.updateTGoods(tGoods));
    }

    /**
     * 删除商品管理
     */
    @ApiOperation("删除商品管理")
    @PreAuthorize("@ss.hasPermi('web:goods:remove')")
    @Log(title = "商品管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Long[] ids) {
        return R.ok(tGoodsService.deleteTGoodsByIds(ids));
    }
}
